/* The run time clock is hard-wired to IRQ8. */
#include <kclock.h>
#include <sbilib_mos.h>
#include <printf.h>

extern void set_timer();

//Overview:
//Use function set_timer to initialize clock interrupt.
//And the run time clock is hard-wired to IRQ8, you can see in handle_sys.
//
//Pre-condition:
//env_init should be executed  before this.
//
//Post-condition:
//You can't run any env directly before this being executed.

void
kclock_init(void)
{
        /* initialize 8253 clock to interrupt 100 times/sec */
	sbi_set_timer(get_time() + 10000000);
//	printf("Current time:%d\n", get_time());
//	u_int64_t i, max = 0, j;
//	for(i=0;i<10000000;i++) {
//		j = get_time();
//		max = j > max ? j : max;
//	}
//	printf("Current time:%d, max = %d\n", get_time(), max);
	set_timer();
}

void
clk_set_next_event(void)
{
	// 10 ms for next clock event
	// Note that timer frequency: 10MHZ.
	sbi_set_timer(get_time() + 100000);
	return;
}
